package com.seventh.parkingrent.dao;

import com.seventh.parkingrent.controller.form.RentMessageFormForFront;
import com.seventh.parkingrent.domain.RentMessage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 订单详情记录表 Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
public interface RentMessageMapper extends BaseMapper<RentMessage> {
    @Select("select DISTINCT u.username from pr_user u,pr_rent_message rm where u.user_id=rm.lessor_id")
    List<String> getLessor();

    @Select("select distinct u.username from pr_user u,pr_rent_message rm where u.user_id=rm.tenantry_id")
    List<String> getTenantry();

    @Select("<script>" +
            "select rm.*,pm.property_name from pr_rent_message rm,pr_property_manager pm " +
            "where rm.property_manager_id =pm.property_manager_id " +
            "and date(rm.rent_start_time) between #{rentStartDateStart} and #{rentStartDateEnd} " +
            "and date(rm.rent_end_time) between #{rentEndDateStart} and #{rentEndDateEnd} " +
            "<if test='status!=null'>and rm.status=#{status} </if>" +
            "<if test='propertyName!=null'>and pm.property_name=#{propertyName} </if>" +
            "<if test='lessorId!=0'>and rm.lessor_id=#{lessorId} </if>" +
            "<if test='tenantryId!=0'>and rm.tenantry_id=#{tenantryId} </if>" +
            "</script>")
    List<RentMessageFormForFront> selectRentMessageByCondition(@Param("status") String status,
                                                               @Param("lessorId") Integer lessorId,
                                                               @Param("tenantryId") Integer tenantryId,
                                                               @Param("rentStartDateStart") Date rentStartDateStart,
                                                               @Param("rentStartDateEnd") Date rentStartDateEnd,
                                                               @Param("rentEndDateStart") Date rentEndDateStart,
                                                               @Param("rentEndDateEnd") Date rentEndDateEnd,
                                                               @Param("propertyName") String propertyName);
}
